<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>智投内容页</title>
    <link rel="stylesheet" type="text/css" href="./css/api.css" />
    <link rel="stylesheet" type="text/css" href="./css/aui.css" />
    <link rel="stylesheet" type="text/css" href="./css/font-awesome.min.css" />
    <link rel="stylesheet" type="text/css" href="./css/styleold.css" />
    <script type="text/javascript" src="./script/api.js"></script>
    <script type="text/javascript" src="./script/aui-tab.js" ></script>
    <link rel="stylesheet" type="text/css" href="./css/aui-slide.css" />
    <script type="text/javascript" src="./script/aui-slide.js"></script>
    <script type="text/javascript" src="./script/base.js"></script>
    <script type="text/javascript" src="./script/doT.min.js"></script>
    <script type="text/javascript" src="./script/jquery-3.2.0.js"></script>
    <script type="text/javascript">
        function closeWin(){
            var refreshUser = 'changeSelect_licai();';
            api.execScript({
                name: 'home',
                script: refreshUser,
            });
            api.closeWin({
            });
        };
    </script>
</head>
<body>
    <div id="list"></div>
    <div class="licai-record-d" id="weidenglu" onclick="weidenglu();">请登录</div>
    <div class="licai-record-d" id="weikaitong" style="display: none;" onclick="weikaitong();">请前往开通存管账户</div>
    <div class="licai-record-d" id="kegoumai" style="display: none;" onclick="kegoumai();">立即购买</div>
</body>

<script type="text/template" id="template">
    <!-- 头部 -->
    <header class="aui-bar aui-bar-nav">
        <a class="aui-pull-left aui-btn" onclick="closeWin()">
            <span class="aui-iconfont aui-icon-left"></span>
        </a>
        <div class="aui-title">{{=it.name}}</div>
    </header>
    
    <!-- 智投内容 -->
    <div class="licai-zhitou-t">
        <p>预期年化利率(%)</p>
        {{=it.rate}}
        <p onclick="buy_people({{=it.time_limit}})"><span class="fa fa-address-book-o"></span>已有<i>{{=it.load_count}}</i>人购买<span class="fa fa-angle-right"></span></p>
        <ul>
            <li><p class="money">{{=it.borrow_amount}}</p>可投金额(元)</li>
            <li><p class="money">{{=it.min_money_format_num}}</p>起投金额(元)</li>
            <li><p>{{=it.time_limit}}</p>项目期限(月)</li>
        </ul>
    </div>
    <div class="licai-zhitou-m">
        <!-- <div class="licai-zhitou-m-t">
            <span>奖励</span>
            多重红包,上不封顶
            <i class="fa fa-angle-right"></i>
        </div> -->
        <ul>
            <li>
                <span class="fa fa-file-text-o"></span>
                <p>购买成功</p>
            </li>
            <li>
                <span class="fa fa-sitemap"></span>
                <p>自动匹配项目</p>
            </li>
            <li>
                <span class="fa fa-thumbs-o-up"></span>
                <p>坐等收益</p>
            </li>
            <div class="licai-zhitou-m-s1"></div>
            <div class="licai-zhitou-m-s2"></div>
        </ul>
    </div>
    <div class="aui-content aui-margin-t-15">
        <ul class="aui-list aui-list-in">
            <li class="aui-list-item aui-list-item-middle">
                <div class="aui-list-item-inner aui-list-item-arrow" onclick="chanpinxiangqing();">
                    <div class="aui-list-item-title">产品详情</div>
                </div>
            </li>
            <li class="aui-list-item aui-list-item-middle">
                <div class="aui-list-item-inner aui-list-item-arrow" onclick="changjianwenti();">
                    <div class="aui-list-item-title">常见问题</div>
                </div>
            </li>
        </ul>
    </div>
</script>

<script type="text/javascript">
    var load_count = '';
    var min_money_format_num = '';
    var borrow_amount = '';
    var rate = '';
    var time_limit = '';
    var add_money = '';

    apiready = function(){
        id = api.pageParam.id;
        // alert(id);
        load_list(id);
        addOb();
        api.addEventListener({
            name: 'keyback'
        }, function(ret, err) {
            closeWin();
        });
    }

    function addOb() {
        api.addEventListener({
            name: 'login_success'
        }, function(ret, err){
            if( ret ){
               load_list(id);
           }else{
               // alert( JSON.stringify( err ) );
           }
       });
    }

    // 加载列表
    function load_list(id) {

        api.showProgress({
            style: 'default',
            animationType: 'fade',
            title: '努力加载中...',
            text: '先喝杯茶...',
            modal: false
        });

        api.ajax({
            url: webAddress+'/index.php?ctl=app_deal&act=licai&id='+id,
            method: 'get',
        },function(ret, err){
            if (ret) {
                // alert($api.jsonToStr(ret));
                if (ret.status == 0) {
                    alert(ret.info);
                }else {
                    // alert( JSON.stringify( ret ) );
                    api.hideProgress();

                    load_count = ret.load_count;
                    min_money_format_num = ret.min_money_format_num;
                    borrow_amount = ret.borrow_amount;
                    rate = ret.rate;
                    rate_month = ret.rate_month;
                    // alert(ret.rate);
                    // alert(ret.rate_month);
                    time_limit = ret.time_limit;
                    // alert(ret.add_money);
                    add_money = ret.add_money;

                    var num = ret.load_list;
                    updateList(ret, num.length);
                }
            } else {
                // alert( JSON.stringify( err ) );
                alert(err.msg);
                api.hideProgress();
                api.closeWin({
                });
            }
        });
    }

    // doT
    function updateList(data, num){

        // alert($api.getStorage('userid'));
        // alert($api.getStorage('is_hrb'));

        if ($api.getStorage('userid') == null || $api.getStorage('userid') == '') {
            $('#weikaitong').hide();
            $('#kegoumai').hide();
            $('#weidenglu').show();
        }else {
            if (!$api.getStorage('is_hrb')) {
                $('#weidenglu').hide();
                $('#kegoumai').hide();
                $('#weikaitong').show();
            }else {
                $('#weikaitong').hide();
                $('#weidenglu').hide();
                $('#kegoumai').show();
            }
        }

        var template = $api.byId('template');
        var dotFn = doT.template(template.innerHTML);
        var html = dotFn(data);
        var list = $api.byId('list');
        $api.html(list, html); 
        $(".money").each(function(){
            // alert($(this).text());
            var tmp = outputmoney($(this).text());
            $(this).text(tmp);
        });
    }

    // 已购人数
    function buy_people(id) {
        api.openWin({
            name: 'licai_record_zhitou',
            url: './licai-record-zhitou.html',
            pageParam: {
                id: id,
                load_count:load_count,
            }
        });
    }

    // 未登录
    function weidenglu() {
        // 跳转登录页面
        api.openFrame({
            name: 'login',
            url: './login.html',
            rect: {
                x: 0,
                y: 0,
                w: 'auto',
                h: 'auto'
            },
            pageParam: {
                login: 'licai'
            },
            bounces: false,
            bgColor: 'rgba(0,0,0,0)',
            vScrollBarEnabled: true,
            hScrollBarEnabled: true
        });
    }

    // 未开通
    function weikaitong() {
        // 跳转开通页面
        api.openFrame({
            name: 'open-bank',
            url: './open-bank.html',
            rect: {
                x: 0,
                y: 0,
                w: 'auto',
                h: '70px',
            },
            pageParam: {
                window: 'licai-zhitou'
            },
            bounces: false,
            bgColor: 'rgba(0,0,0,0)',
            vScrollBarEnabled: true,
            hScrollBarEnabled: true
        });

        api.openFrame({
            name: 'bank',
            url: './bank.html',
            rect: {
                x: 0,
                y: '70px',
                w: 'auto',
                h: 'auto'
            },
            pageParam: {
                name: 'test'
            },
            bounces: false,
            bgColor: 'rgba(0,0,0,0)',
            vScrollBarEnabled: true,
            hScrollBarEnabled: true
        });
    }

    // 可购买
    function kegoumai() {

        if (borrow_amount == 0) {
            api.toast({
                msg: '没有可投金额，无法购买',
                duration: 2000,
                location: 'bottom'
            });
            return false;
        }

        api.openWin({
            name: 'licai-buy',
            url: './licai-buy.html',
            pageParam: {
                borrow_amount: borrow_amount,  // 可投金额
                min_money_format_num:min_money_format_num,  // 起投金额
                rate:rate,  // 利率(期末获利)
                is_zhitou:1,
                rate_month:rate_month,// 利率(分期获利)
                time_limit:time_limit,  // 期限
                id:id,  // id
                add_money:add_money  // 加减金额数
            }
        });
    }

    function closeBank(){
        api.closeFrame({
            name: 'bank'
        });
    }

    function changjianwenti() {

        api.openWin({
            name: 'ques-list',
            url: './ques-list.html',
            pageParam: {
                name: 'test'
            }
        });
    }

    function chanpinxiangqing() {

        api.openWin({
            name: 'licai-chanpinxiangqing',
            url: './licai-chanpinxiangqing.html',
            pageParam: {
                id: id
            }
        });
    }

</script>
</html>